package com.yue.springDemo.framework.expection;

import com.yue.springDemo.business.bean.ResponseResult;
import com.yue.springDemo.commons.logger.MyLoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;

/**
 * 统一的异常处理(已废弃，使用Exception2Controller)
 * @see com.yue.springDemo.framework.expection.Exception2Controller
 */
// @Controller
@Deprecated
public class ExceptionController implements ErrorController {

    @Autowired
    private MyLoggerFactory logger;

    @Override
    public String getErrorPath() {
        return "/error";
    }

    /**
     * 404时，不会抛出异常，所以使用springboot自带异常controller
     *
     * @param request 请求
     * @return 结果
     */
    @RequestMapping("/error")
    @ResponseBody
    public ResponseResult error(HttpServletRequest request) {
        logger.error(request.getRequestURL().append("该接口不存在").toString());
        ResponseResult responseResult = ResponseResult.error("404", "该接口不存在");
        return responseResult;
    }

}
